//
//  HHYNaviVC.m
//  大股票
//
//  Created by apple on 2019/8/15.
//  Copyright © 2019 apple. All rights reserved.
//

#import "HHYNaviVC.h"

#define kShowTabbarClassNameArr @[@"HHYStockCalculateVC",@"FTQMineController"]

@interface HHYNaviVC ()

@end

@implementation HHYNaviVC

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self setUpNavigationBar];
    self.hidesBottomBarWhenPushed = YES;
    
    __weak HHYNaviVC *weakSelf = self;
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.delegate = weakSelf;
        self.delegate = weakSelf;
        self.interactivePopGestureRecognizer.enabled = YES;
    }
}

- (void)setUpNavigationBar {
    //自定义返回按钮图片
    [self.navigationBar setTintColor:[UIColor blackColor]];
    
    //导航
    self.navigationBar.barStyle = UIBarStyleDefault;
    [self.navigationBar setTranslucent:NO];
    [self.navigationBar setShadowImage:[UIImage new]];
    //    self.navigationBar.barTintColor = MAINCOLOR;
    //    self.navigationBar.barTintColor = UIColor.blackColor;
    
    
    //隐藏系统导航栏返回箭头
    UIImage *image = [UIImage new];
    
    if (@available(iOS 11.0, *)) {
        image = [UIImage new];
        self.navigationBar.backIndicatorImage = image;
        self.navigationBar.backIndicatorTransitionMaskImage = image;
    }
}


- (void)pushViewController:(UIViewController *)viewController
                  animated:(BOOL)animated {
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)] &&
        animated == YES) {
        self.interactivePopGestureRecognizer.enabled = NO;
    }
    
    // 首页不需要隐藏tabbar
    NSString *className = NSStringFromClass([viewController class]);
    
    //是否显示tabbar
    viewController.hidesBottomBarWhenPushed = ![kShowTabbarClassNameArr containsObject:className];
    
    [super pushViewController:viewController animated:animated];
}

- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated {
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)] &&
        animated == YES) {
        self.interactivePopGestureRecognizer.enabled = NO;
    }
    
    return [super popToRootViewControllerAnimated:animated];
}

- (NSArray *)popToViewController:(UIViewController *)viewController
                        animated:(BOOL)animated {
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.enabled = NO;
    }
    return [super popToViewController:viewController animated:animated];
}

#pragma mark UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController
       didShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animate {
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.enabled = YES;
    }
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    if ([gestureRecognizer isEqual:self.interactivePopGestureRecognizer] &&
        self.viewControllers.count > 1 &&
        [self.visibleViewController isEqual:[self.viewControllers lastObject]]) {
        return YES;
    } else {
        return NO;
    }
}

@end
